import { defineStore } from 'pinia'
import { ref } from 'vue'
import axios from 'axios'
export const useBacktestStore = defineStore('backtest', () => {
    const form = ref(null);
    function setForm(backtest_form){
        form.value = backtest_form;
        console.log(form.value);
    }
    async function getItemListByDescription(scenario_id,description) {
        let sorted_item_list ;
        await axios.post("http://127.0.0.1:5000/get_item_list_by_description", { 
        "scenario_id":scenario_id,    
        "description": description })
        .then(response => {
          sorted_item_list = response.data
        })
        return sorted_item_list;
    }

    async function startBacktest(backtest_form){
        let report;
        await axios.post("http://127.0.0.1:5000/start_backtest", {
            backtest_form:backtest_form
    }).then(response=>{
       report = response.data;
    })
    return report;
}
    return { getItemListByDescription,startBacktest,setForm,form}
}
    , {
        persist: {
            enabled: true
        }
    })
